package com.tongqin.distributed.type;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author yuantongqin
 * @date 2018/8/24 上午11:24
 */
@MappedJdbcTypes(value = {JdbcType.VARCHAR})
public class TestTypeHandler extends BaseTypeHandler<String> {
   @Override
    public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
//       ps.setString(i,parameter);
        ps.setString(i, parameter+"=思密达");
    }

    @Override
    public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
//       rs.getString(columnName);
        return rs.getString(columnName);
    }

    @Override
    public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
//       rs.getString(columnIndex)
        return rs.getString(columnIndex);
    }

    @Override
    public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return cs.getString(columnIndex);
    }
}
